package com.eco.fanliapp.admin.controller.web;


import com.alibaba.fastjson.JSONObject;
import com.eco.fanliapp.admin.common.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.service.IStatisticsService;
import com.eco.fanliapp.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 后台管理统计接口
 */
@RestController
@RequestMapping("/web/data/statistics")
public class StatisticsController extends BaseController {

    @Autowired
    private IStatisticsService iStatisticsService;

    @GetMapping("/list")
    public ServerResponse staticList(){
        JSONObject jsonObject =iStatisticsService.staticList();
        if(jsonObject !=null){
            return ServerResponse.createBySuccess("获取成功",jsonObject);
        }else{
            return ServerResponse.createByErrorMessage("AdminServerTask——定时任务未开启");
        }
    }
//
//    /**
//     *
//     * @param companyId
//     * @return
//     */
//    @GetMapping("/otherList")
//    public ServerResponse otherList(Integer companyId ){
//        if(companyId == null){
//            UserVO userVO = getAuthentication();
//            if (userVO.getCompanyId() != 1) {
//                companyId = userVO.getCompanyId();
//            }
//        }
//
//        JSONObject jsonObject =iStatisticsService.otherList(companyId);
//        return ServerResponse.createBySuccess("获取成功",jsonObject);
//    }

    @GetMapping("/jsonList")
    public ServerResponse jsonList(Integer companyId ){
        if(companyId == null){
            UserVO userVO = getAuthentication();
            if (userVO.getCompanyId() != 1) {
                companyId = userVO.getCompanyId();
            }
        }

        JSONObject jsonObject =iStatisticsService.jsonList(companyId);
//        iStatisticsService.jsonListTask(companyId);
        if(jsonObject !=null){
            return ServerResponse.createBySuccess("获取成功",jsonObject);
        }else{
            return ServerResponse.createByErrorMessage("AdminServerTask——定时任务未开启");
        }
    }
    @GetMapping("/jsonTabList")
    public ServerResponse jsonTabList(Integer companyId,int type ){
        if(companyId == null){
            UserVO userVO = getAuthentication();
            if (userVO.getCompanyId() != 1) {
                companyId = userVO.getCompanyId();
            }
        }

        JSONObject jsonObject =iStatisticsService.jsonTabList(companyId,type);
//        iStatisticsService.jsonTabListTask(companyId,type);
        if(jsonObject !=null){
            return ServerResponse.createBySuccess("获取成功",jsonObject);
        }else{
            return ServerResponse.createByErrorMessage("AdminServerTask——定时任务未开启");
        }
    }

    /**
     * 获取友盟的数据
     * @return
     */
    @GetMapping("/jsonUmengList")
    public ServerResponse jsonUmengList(Integer companyId){
        if(companyId == null){
            UserVO userVO = getAuthentication();
            if (userVO.getCompanyId() != 1) {
                companyId = userVO.getCompanyId();
            }
        }
        JSONObject jsonObject =iStatisticsService.jsonUmengList(companyId);
        if(jsonObject !=null){
            return ServerResponse.createBySuccess("获取成功",jsonObject);
        }else{
            return ServerResponse.createByErrorMessage("umeng接口异常");
        }
    }
}
